
from Tools.filter_def_names import filter_func_names


def count_lines(file_path: str) -> int:
    """统计给定文件的行数"""
    with open(file_path, 'r', encoding='utf-8') as f:
        return sum(1 for line in f)
    
def print_configuration(analysis_flag, filter_depth, filter_mode, src_directory, user_root_name, target_subroutine):
    print(f"Analysis Flag: {analysis_flag}")
    print(f"Filter Depth: {filter_depth}")
    print(f"Filter Mode: {filter_mode}")
    print(f"Source Directory: {src_directory}")
    print(f"User Root Name: {user_root_name}")
    print(f"Target Subroutine: {target_subroutine}")

def print_results(output_file, analysis_file, filter_mode, filter_depth):
    # 统计两个输出文件的行数
    tree_line_count = count_lines(output_file)
    analysis_line_count = count_lines(analysis_file)
    print(f"输出文件 '{output_file}' 的行数: {tree_line_count}")
    print(f"输出文件 '{analysis_file}' 的行数: {analysis_line_count}")
    print(f"使用的过滤模式: {filter_mode}")
    if isinstance(filter_depth, dict):
        for mode, depth in filter_depth.items():
            print(f"{mode}模式过滤深度: {depth}")
    else:
        print(f"过滤深度: {filter_depth}")
    # print(f'filted function names: {filter_func_names}')

def set_analysis_parameters(analysis_flag,CODE_DIR):
    
    if analysis_flag == "drp4dvar":
        src_directory = [CODE_DIR + 'src/', CODE_DIR + 'lib/']
        user_root_name = "drp4dvar_driver"
        target_subroutine = "minimize_cg"
    elif analysis_flag == "gsi":
        src_directory = [CODE_DIR + 'gsi_src/']
        user_root_name = "gsi"
        target_subroutine = "pcgsoi"
    else:
        print("错误：无效的分析标志")
        # exit(1)
    
    return src_directory, user_root_name, target_subroutine